﻿var picMaterial = {};
picMaterial.NameMat = null;
picMaterial.CodeMat = null;
$(function () {
    $("#tbStorage").datagrid({
        url: '/Logic/SM/PurchaseStorageAjax.aspx?method=GetStoreList',
        loadMsg: '数据加载中请稍后……',
        pagination: true,
        rownumbers: true,
        idField: "Id",
        singleSelect: true,
        pageSize: 10,
        queryParams: com.serializeSearchArray("form1"),
        pageList: [10, 20, 30],
        frozenColumns: [[
            { field: 'ck', checkbox: true, width: 30 },
            { field: 'StorageNum', title: '入库单号', width: 100 },
               { field: 'ManifestNum', title: '货单单号', width: 100 },
               { field: 'ProTrack', title: '计划跟踪号', width: 100 },
               { field: 'MaterialCode', title: '物料编码', width: 100 }
        ]],
        columns: [[
               { field: 'MaterialName', title: '物料名称', width: 100 },
               { field: 'Model', title: '规格型号', width: 100 },
               { field: 'Textures', title: '材质', width: 100 },
               { field: 'Length', title: '长', width: 100 },
               { field: 'Width', title: '宽', width: 100 },
               { field: 'Units', title: '单位', width: 100 },
               { field: 'CunHuoNum', title: '库存数量', width: 100 },
               { field: 'ZhangNum', title: '张（支）', width: 100 },
               { field: 'Warehouse', title: '仓库', width: 100 },
               { field: 'StorageBin', title: '仓位', width: 100 },
               { field: 'BatchNum', title: '批号', width: 100 },
               { field: 'SaleMan', title: '业务员', width: 100 },
               { field: 'OrderNum', title: '订单号', width: 100 },
               { field: 'SupplierName', title: '供应商名称', width: 100 },
               { field: 'PlanMode', title: '计划模式', width: 100 },
               { field: 'IdentNum', title: '标识号', width: 100 },
               { field: 'QATimeStart', title: '质保起始时间', width: 100 },
               { field: 'QATime', title: '质保期/天', width: 100 },
               { field: 'QATimeEnd', title: '质保到期时间', width: 100 },
               { field: 'Note', title: '备注', width: 100 },
               { field: 'HeadNote', title: '表头备注', width: 100 }
        ]],
        singleSelect: false,
        pageSize: 20,
        pageList: [20, 50, 100],
        striped: true,
    });
    $("#materialName").change(function () {
        picMaterial.ReloadGrid();
    });
    $("#materialCode").change(function () {
        picMaterial.ReloadGrid();
    });
    $.extend(com.dialogObj, { title: "选择物料", width: 700, height: 450 });
    $("#DemandPlanDiv").dialog(
            com.dialogObj
         );
    $("#DemandPlanDiv").dialog("close");
})
picMaterial.ReloadGrid = function () {
    var name = $("#materialName").val();
    var code = $("#materialCode").val();
    picMaterial.para = [{ Field: "MaterialName", Value: name, Operator: "co" }, { Field: "MaterialCode", Value: code, Operator: "co" }];
    $("#tbStorage").datagrid("reload", {
        SearchData: JSON.stringify(picMaterial.para)
    });
}
picMaterial.Cancel = function () {
    $("#DemandPlanDiv").dialog("close");
}
//picMaterial.Confirm = function () {
//    var row = $("#tbStorage").datagrid("getSelected");
//    if (row) {
//        picMaterial.NameMat.textbox("setText", row.UserName);
//        picMaterial.NameMat.textbox("setValue", row.UserName);
//        picPer.NameMat.nextAll("input[type=hidden]:first").val(row.ID);

//        $("#DemandPlanDiv").dialog("close");
//    }
//    else {
//        com.message("information", "请选择一条数据");
//    }

//}

picMaterial.open = function (target) {
    picMaterial.NameMat = target;
    $("#DemandPlanDiv").dialog("open");
}